package edu.xkd.slice;

import edu.xkd.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.window.dialog.ToastDialog;

//  主应用里的主页面
public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        // 关联一个界面布局文件
        super.setUIContent(ResourceTable.Layout_ability_main);

        // 写关于界面的后台业务逻辑
        //  获取界面中按钮对象
        Button button_01= (Button) this.findComponentById(ResourceTable.Id_button_01);
        Button button_02= (Button) this.findComponentById(ResourceTable.Id_button_02);
        //  为按钮对象添加单击事件
        /*
        * new 接口（）{
        *    实现接口里的方法
        * }
        *
        *
        * */
        button_01.setClickedListener(new Component.ClickedListener() {

            @Override
            public void onClick(Component component) {
                /*
                * Javascript   alter()
                *
                *
                * */
                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                toastDialog.setText("按钮被单击");
                toastDialog.show();
            }
        });

        /*
        * hmos特有的绑定事件
        *
        * */
        button_02.setClickedListener(this::clickedListenerButton02);

    }

    private void clickedListenerButton02(Component component) {
        ToastDialog toastDialog = new ToastDialog(this);
        toastDialog.setText("ohos特有的绑定事件处理方法");
        toastDialog.show();
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
